<h2><%= @tag.name %></h2>
<%= error_messages_for :tag %>
<%- if can_wrangle? -%>
  <p><%= link_to 'Edit'.t + ' ' + @tag.name, edit_tag_path(@tag) %></p>
<%- end -%>

<p><%=h "This tag belongs to the".t %> <%= @tag.class::NAME %> <%=h "Category".t %>.</p>

<%- if @tag.canonical -%>
  <p><%=h 'This is a common tag. You can use this tag to'.t %> 
    <%= link_to 'filter works'.t ,     
        tag_works_path(@tag) %>.
  </p>
<%- end -%>

<%- if @tag.is_a?(Rating) && @tag.adult -%>
  <p><%=h 'This tag indicates adult content.'.t %></p>
<%- end -%>


<%- unless @tag.ambiguities.blank? -%>
  <p><%=h 'Tags which disambiguate here:'.t %></p>
  <%- @tag.ambiguities.each do |ambiguous| %>
    <%= link_to_tag ambiguous %>
  <%- end -%>
<%- end -%>

<% if @tag.is_a?(Fandom) %>
  <p><%=h 'Parent tags (more general):'.t %></p>
  <%- (@tag.parents + [@tag.media]).uniq.compact.sort.each do |parent| %>
    <%= link_to_tag parent %>
  <%- end -%>
<% else %>
  <%- unless @tag.parents.blank? -%>
    <p><%=h 'Parent tags (more general):'.t %></p>
    <%- @tag.parents.sort.each do |parent| %>
      <%= link_to_tag parent %>
    <%- end -%>
  <%- end -%>
<%- end -%>

<%- if @tag.merger -%>
  <p><%=h 'This tag has been merged into'.t %> <%= link_to_tag @tag.merger %> <%=h 'for filtering.'.t %></p>
  <p><%=h 'Works tagged with this tag will show up in'.t %> <%= link_to @tag.merger.name + "'s".t, tag_works_path(@tag.merger) %> <%=h 'filter.'.t %>
<%- end -%>

<%- unless @tag.mergers.blank? -%>
  <p><%=h 'Tags with the same meaning:'.t %></p>
  <%- @tag.mergers.each do |merger| %>
    <%= link_to_tag merger %>
  <%- end -%>
<%- end -%>

<%- unless @tag.children.blank? -%>
  <% if @tag.is_a?(Ambiguity) %>
    <p><%=h 'Disambiguators:'.t %></p>
  <% else %>
    <p><%=h 'Child tags (more specific):'.t %></p>
  <% end %>
  <%- @tag.children.uniq.compact.sort.group_by(&:type).each do |type, tags| %>
    <p><%= type.pluralize %>:</p>
    <% tags.each do |child| %>
      <%= link_to_tag child %>
    <%- end -%>
  <%- end -%>
<%- end -%>

<%- if @works -%>
  <% if @tag.is_a?(Ambiguity) %>
    <p><%=h 'This tag is ambiguous and can not be filtered on.'.t %><p>
  <% else %>
    <p><%=h "This tag has not been marked common and can't be filtered on (yet).".t %><p>
  <% end %>
  <p><%=h 'Works which have used it as a tag:'.t %></p>
  <% paginated_section @works, {:previous_label => '&laquo; Previous'.t, :next_label => 'Next &raquo;'.t} do %>
    <ul class="work-list">
      <%- for work in @works -%>
        <%= render :partial => 'works/work_blurb', :locals => {:work => work} %>
      <%- end -%>
    </ul>
  <% end %>
<%- end -%>
